var ns;
var app = new Vue({
    el: '#app',
    data: {
       ID:0,
       EncriptID:'',
        form: {
        },
        showdetail:false,
        activetab:1,
        //工作记录
        gzCount:0,
        gzlist:[],
        //巡查问题
        xclist:[],
    },
    methods: {
        select_tab(value){
            this.activetab=value;
        },
        get_homedata(){
            var that = this;
            var options = {};
            options.EncriptID = that.EncriptID;    
            options.action = "getpatroldetail";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if(data.status){
                        that.form = data.data;
                        that.ID=that.form.ID; 
                        that.get_gz_data();
                        that.get_xc_data();
                    }
                    else{
                        if(data.error){
                            api.toast({
                                msg: data.error,
                                duration: 2000,
                                location: 'bottom'
                            });
                            return
                        }
                    } 
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },  
        get_gz_data(){
            var that = this;
            var options = {};
            options.action = "getpatroltasklistbypatrolid";
            options.ID = that.ID;    
            options.Status=0;
            options.StartTime='';
            options.EndTime='';
            options.pageindex=0;
            options.pagesize=10;
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if(data.status){
                        that.gzCount=data.data.count;
                        that.gzlist=data.data.list;
                    } 
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        }, 
        get_xc_data(){
            var that = this;
            var options = {};
            options.ID = that.ID;    
            options.action = "getpatroltaskanomalyreportlist";
            // console.log(JSON.stringify(options));
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if(data.status){
                        that.xclist=data.data.list;
                    } 
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        }, 
        //查看详情
        doOpenDetail(){
            this.showdetail=!this.showdetail;
        },
        open_details: function(item) {
            ns.openWin('patrolplan_details_frm_task', '工作记录详情', {
                id: item.ID
            });
        },
        doRecordAdd(){
            var that = this;
            ns.openWin('patrolplan_addfrm', '新增记录',{
                IsHome:true,//是否是首页
                PatrolID:that.form.ID,
                PatrolName:that.form.PatrolName,
                projectid:that.form.ProjectID,
                name:that.form.ProjectName,
            });
        },
        doOpenMoreRecord(){
             var that = this;
             ns.openWin('patrolplan_homelist', '记录列表', {
                 id: that.ID,
             });
         },
         open_list(item){
            var that = this;
            ns.openWin('home_task_con_frm', '任务详情', {
                id: item.GongdanID,
                isviewdetail: true
            });
         },
    }
});

apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.ID = api.pageParam.ID || 0;
    app.EncriptID = api.pageParam.EncriptID || '';
    if(app.EncriptID!=''){
        app.get_homedata();
    }
    api.addEventListener({
        name: 'reloadhomedetail'
    }, function(ret, err) {
        app.get_homedata();
    });
}
